

public class Main {

	/**
	 * @param args
	 * 
	 * Your googlecode.com password: xz3Dq4uy6zk7
	 * 
	 * This password is used by project members when checking out or committing 
	 * source code changes, or when using command-line tools to upload files to 
	 * the project "Downloads" tab.
	 * 
	 * TODO:
	 *  Recursively traversing files and folders using Java File API:
	 *  http://www.javabeat.net/tips/19-recursively-traversing-files-and-folders-usin.html
	 *  
	 *  API Java 6:
	 *  http://java.sun.com/javase/6/docs/api/
	 *  
	 *  - Verificar se os caminhos informados correspodem a diretorios
	 *  - File.isDirectory() and File.isFile() returns false and true
	 *  
	 *  Detect File Modification (in both File and Directory):
	 *   http://www.rgagnon.com/javadetails/java-0490.html
	 *  
	 *  Understanding the TreeModel:
	 *   http://java.sun.com/products/jfc/tsc/articles/jtree/
	 *  
	 *  Watching A Directory for Changes and File Change Notification in NIO.2:
	 *   http://blogs.sun.com/thejavatutorials/entry/watching_a_directory_for_changes
	 *   
	 *  File/directory polling to detect change
	 *   http://www.rgagnon.com/javadetails/java-0617.html
	 *   
	 *   Create a checksum for a file
	 *   http://www.jguru.com/faq/view.jsp?EID=216274
	 *   
	 *   Create a MD5 checksum
	 *   http://www.rgagnon.com/javadetails/java-0416.html
	 *  
	 */
	public static void main(String[] args) {
		
		/**
		 * Exits if user does not pass 2 arguments exactly
		 *  
		 * Windows: "C:\\myDocuments\\myFile.txt"
		 * Windows: "C:\\myDocuments"
		 * Linux:   "/home/bruno/testmirror/test1"
		 */
		if (args.length != 4) {
			System.err.println("4 and only 4 arguments must be passed to the program!\n");
			System.err.println("============================================");
			System.err.println("Usage:   java -jar MirrorAgent.jar path1 path2 updateTime killFileName");
			System.err.println("");
			System.err.println("         path1:        String");
			System.err.println("         path2:        String");
			System.err.println("         updateTime:   integer");
			System.err.println("         killFileName: String");
			System.err.println("Example: java -jar MirrorAgent.jar /home/user/dir1 /home/user/dir2 30 KILL_AG.$$$");
			System.err.println("============================================");
//			System.err.println("       Usage:");
			System.exit(-1);
		}
		
		
		/**
		 * Exits if 3rd argument passed is not a integer number
		 * 
		 */
		if (args.length != 4) {
			System.err.println("4 and only 4 arguments must be passed to the program!\n");
			System.err.println("============================================");
			System.err.println("Usage:   java -jar MirrorAgent.jar path1 path2 updateTime killFileName");
			System.err.println("");
			System.err.println("Example: java -jar MirrorAgent.jar /home/user/dir1 /home/user/dir2 30 KILL_AG.$$$");
			System.err.println("============================================");
//			System.err.println("       Usage:");
			System.exit(-1);
		}
		
		int updateTime = 1;
		try {
			updateTime = Integer.parseInt(args[2]);
		} catch(NumberFormatException nfe) {
			System.err.println("============================================");
			System.err.println("The 3rd argument "+args[2]+" is not an integer number!\n");
			System.err.println("============================================");
			System.exit(-1);
		}

		Mirror mirror = new Mirror(args[0], args[1], updateTime, args[3]);
		
		// START TRACKING/MONITORING
		mirror.startProgram();
		
		System.out.println("FIM DO PROGRAMA");
		
	}

}
